<template>
  <el-container>
    <el-main>
      <el-table :data="tableData">
        <el-table-column prop="user" label="用户" width="140"></el-table-column>
        <el-table-column
          prop="title"
          label="文章名"
          width="120"
        ></el-table-column>
        <el-table-column prop="content" label="内容"></el-table-column>
        <el-table-column prop="up" label="点赞"></el-table-column>
        <el-table-column label="时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | newTime}}
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>
<script>
import { getArticle } from '@/api/article'

export default {
  created () {
    getArticle()
      .then(res => {
        this.tableData = res.data
      })
      .catch(err => {
        console.log(err)
      })
  },
  data () {
    return {
      tableData: []
    }
  },
  filters: {
    newTime: function (data) {
      data = new Date(data)
      return `
        ${data.getFullYear()}-${data.getMonth()}-${data.getDate()}
        ${data.getHours()}:${data.getMinutes()}:${data.getSeconds()}
      `
    }
  }
}
</script>

<style></style>
